package com.fitsoftwareprocess.mobilemap;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.fitsoftwareprocess.mobilemap.bus.Service;
import com.fitsoftwareprocess.mobimap.dto.Coordinate;
import com.fitsoftwareprocess.mobimap.dto.ListDichVuAdapter;
import com.fitsoftwareprocess.mobimap.dto.PlaceInfo;
import com.fitsoftwareprocess.mobimap.dto.PlaceTypeInfo;
import com.fitsoftwareprocess.mobimap.dto.ServiceDTO;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputFilter.LengthFilter;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
//import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
//import com.fitsoftwareprocess.mobilemap.bus;
import android.widget.EditText;
public class UpdateService extends Activity implements android.view.View.OnClickListener{
	

	ArrayList<ServiceDTO> array;
	ListDichVuAdapter arrayAdapter;
	
	static InputStream is = null;
    static JSONObject jObj = null;
   // JSONArray dichvu= null;
    static String json2 ;
	Service myservice = new Service("http://tempuri.org/", "http://10.0.2.2:1609/Service1.asmx");
	ArrayList<ServiceDTO> mangketqua = new ArrayList<ServiceDTO>();
	
	Button them ;
	EditText Ten;
	EditText Diachi;
	Spinner DichVu;
	EditText Kinhdo;
	EditText Vido;
	
	String longitude="0";
	String latitude="0";
	String fullname="";
	String address="";
	String id="";
	@Override
	
    public void onCreate(Bundle savedInstanceState) 
	{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addservice);
        Ten  = (EditText)findViewById(R.id.editTextName_Addservice);
	    Diachi = (EditText)findViewById(R.id.editTextAddress_Addservice);    
	    DichVu = (Spinner)findViewById(R.id.spinnerTypeService_Addservice);        
	    Kinhdo = (EditText)findViewById(R.id.editTextLat_Addservice);	        
	    Vido = (EditText)findViewById(R.id.editTextLong_Addservice);	        
	    them = (Button)findViewById(R.id.buttonAdd_Addservice);
		them.setOnClickListener(this);
		
		
		fullname = getIntent().getExtras().getString("FullName");
		address = getIntent().getExtras().getString("Address");
		id = getIntent().getExtras().getString("ID");
		longitude = getIntent().getExtras().getString("Longitude");
		latitude = getIntent().getExtras().getString("Latitude");
		
		
		Ten.setText(fullname);
		Diachi.setText(address);
        Kinhdo.setText(longitude);
        Vido.setText(latitude);
        
       List<String> list = new ArrayList<String>();
    	list.add("Bưu Điện");
    	list.add("Bảo Tàng");
    	list.add("Bệnh viện");
    	list.add("Chợ");
    	list.add("Chùa");
    	list.add("Công viên");
    	list.add("Khách sạn");
    	list.add("Ngân hàng");
    	list.add("Nhà thờ");
    	list.add("TT TDTT");
    	list.add("Lãnh sự quán");
    	list.add("Trường học");//781
    	list.add("UBND");//792
    	list.add("Trạm ATM");//889
    	list.add("Cây Xăng");//891
    	list.add("Nhà vệ sinh công cộng");//895
    	list.add("Quán cà phê");//890
    	list.add("Siêu thị");//894
    	list.add("Nhà sách");//901
    	list.add("Chung cư");//898
    	list.add("Rạp chiếu phim");//899
    	
    	
    	ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
    			android.R.layout.simple_spinner_item, list);
    		dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    		DichVu.setAdapter(dataAdapter);
        
	}
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		int Loaidichvu=1;
		switch(v.getId())
		{
		case R.id.buttonAdd_Addservice :
		{		
			switch(DichVu.getSelectedItemPosition())
					{
				case 1://BUUDIEN
				{
					Loaidichvu =1;
					break;
				}
				case 2://BAOTANG
				{
					
					Loaidichvu =42;
					break;
				}
				case 3://BENHVIEN
				{
		    	Loaidichvu =51;
				break;
				}
				case 4://BQLCHO
				{
		    	Loaidichvu =104;
				break;
				}
				case 5://CHUA
				{
		    	Loaidichvu =112;
				break;
				}
				case 6://CONGVIEN
				{
		    	Loaidichvu =136;
				break;
				}
				case 7://KHACHSAN
				{
		    	Loaidichvu =383;
				break;
				}
				case 8://NGANHANG
				{
		    	Loaidichvu =483;
				break;
				}
				case 9:// GIAOXU
				{
		    	Loaidichvu =509;
				break;
				}
				case 10://TT TTD
				{
		    	Loaidichvu =623;
				break;
				}
				case 11://TONG LANHSUQUAN
				{
		    	Loaidichvu =750;
				break;
				}
				case 12://781//TRUONG
				{
		    	Loaidichvu =781;
				break;
				}
				case 13://792//
				{
		    	Loaidichvu =792;
				break;
				}
				case 14://889
				{
		    	Loaidichvu =889;
				break;
				}
				case 15://891
				{
		    	Loaidichvu =891;
				break;
				}
				case 16://895
				{
		    	Loaidichvu =895;
				break;
				}
				case 17://890
				{
		    	Loaidichvu =890;
				break;
				}
				case 18://894
				{
		    	Loaidichvu =894;
				break;
				}
				case 19://901
		    	Loaidichvu =901;
				break;
				case 20://898
				{
		    	Loaidichvu =898;
		    	break;
				}
				case 21://899
				{
		    	Loaidichvu =899;
				break;
				}
				
			}
			String loaidichvu= String.valueOf(Loaidichvu);
			if(Kinhdo.getText().toString() != "" && Vido.getText().toString() != "")
			{
				myservice.deleteService(id);
				myservice.Addservice(Ten.getText().toString(), Diachi.getText().toString(), loaidichvu, Vido.getText().toString(), Kinhdo.getText().toString());
				Toast.makeText(UpdateService.this, "Cập nhật dịch vụ thành công", Toast.LENGTH_SHORT).show();
						
			}
			break;
	
		}
			
		}
		
	}

}
